import { UserProfilesAPI } from "@/request/api"
export default {
    namespaced: true,
    // 共享的数据
    state: {
        userInfo: {
            nickName: 'name',
            coin: 80,
            headImg: require("../../assets/img/userImg.f8bbec5e.png")
        },
        cartTotal: 10
    },

    mutations: {
        // 修改数据 是否显示登录模态框状态
        changeUserInfo(state, payload) {
            // console.log("修改vuex中用户信息", payload);
            state.userInfo = payload.userInfo
            state.cartTotal = payload.cartTotal
        },
        // 初始化
        initUserInfo(state) {
            console.log("初始化新鞋...");
            state.userInfo = {
                nickName: '',
                coin: 0,
                headImg: require("../../assets/img/userImg.f8bbec5e.png")
            }
        }
    },
    actions: {
        async asyncChangeUserInfo(context) {
            // 1.请求用户信息
            let user = await UserProfilesAPI()
            console.log("user:", user.data);
            // 2.调用mutations更新用户信息
            context.commit("changeUserInfo", user.data)
        }
    }


}